package me.xhy.java.springboot3.webflux.s03exceptionandparam;

import org.springframework.http.codec.multipart.FilePart;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

import java.io.File;

@Controller
public class S034File {

  @PostMapping("/fileold")
  public Mono<String> file(/*ServerWebExchange exchange, 等其他参数*/MultipartFile file) throws Exception {
    file.getInputStream();
    System.out.println(file.getOriginalFilename());


    return Mono.just(file.getOriginalFilename());
  }

  @PostMapping("/filenew")
  public Mono<String> filenew(@RequestPart("meta-date") FilePart metadata) {

    metadata.filename();//文件名
    metadata.name(); // 文件筐的名
    metadata.transferTo(new File("")); // 零拷贝技术

    return Mono.empty();
  }


}
